#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#include <iterator>
#include <set>
#include <stdio.h>
#include <functional>
using namespace std;
int main()
{
	int t; scanf("%d", &t);
	while (t--)
	{
		int n; scanf("%d", &n);
		priority_queue<int, vector<int>, greater<int> >vec;
		for (int i = 0; i < n; i++)
		{
			int x;
			scanf("%d", &x);
			vec.push(x);
		}
		n--;
		long long int ans = 0;
		if (n == 0)ans = vec.top();
		while (n--)
		{
			long long int min_1, min_2;
			min_1 = vec.top();
			vec.pop();
			min_2 = vec.top();
			vec.pop();
			ans += min_1 + min_2;
			vec.push(min_1 + min_2);
		}
		printf("%lld\n", ans);
	}
	return 0;
}